options compress=YES;
libname manasi ''; 

* MERGE 2002 CDR ELIGIBLES WITH THEIR SSR-OUTCOMES DATA;
proc sort data=manasi.cdrdata2_2002;
	by ssn;
run;

data manasi.kids_cdr02_mergeall_full;
	merge 	
			manasi.cdrdata2_2002 
			(rename=(ssn=hun dob=dob_cdr dobyy=dobyy_cdr sex=sex_cdr) in=fromcdrx
			drop=dis_off_cd score score_adr adj_level cus_cd guard_st 
			title_xvi ssr_sec ds_dia_cd ds_med_rea ds_per_dis bod_831 pri_831
			sec_831 med_831_re med_831_list dia_831 edu_831 adj_cdr body_833
			pri_833 sec_833 med_833_list dia_833 med_833_re dcf_pri_cd dcf_sec_cd)

			manasi.kids_ssr_full_nwithsummfypar 
			(in=fromssrx where=(n_estpd_num<20011001 & n_estpd_next>=20011001)
			drop=aptype mbrlaf cpstat race dt8080 xmitdo dencde dendte zebind
			do reptyp repcus n_diag2:);

	by hun; 
	fromcdr = fromcdrx;
	fromssr = fromssrx;
run;


* MERGE 2003 CDR-ELIGIBLES WITH THEIR SSR-OUTCOMES DATA;
proc sort data=manasi.cdrdata2_2003;
	by ssn;
run;

data manasi.kids_cdr03_mergeall_full;
	merge 	
			manasi.cdrdata2_2003 
			(rename=(ssn=hun dob=dob_cdr dobyy=dobyy_cdr sex=sex_cdr) in=fromcdrx
			drop=dis_off_cd score score_adr adj_level cus_cd guard_st 
			title_xvi ssr_sec ds_dia_cd ds_med_rea ds_per_dis bod_831 pri_831
			sec_831 med_831_re med_831_list dia_831 edu_831 adj_cdr body_833
			pri_833 sec_833 med_833_list dia_833 med_833_re dcf_pri_cd dcf_sec_cd)

			manasi.kids_ssr_full_nwithsummfypar 
			(in=fromssrx where=(n_estpd_num<20021001 & n_estpd_next>=20021001)
			drop=aptype mbrlaf cpstat race dt8080 xmitdo dencde dendte zebind
			do reptyp repcus n_diag2:);

	by hun; 
	fromcdr = fromcdrx;
	fromssr = fromssrx;
run;


* MERGE 2004 CDR-ELIGIBLES WITH THEIR SSR-OUTCOMES DATA;
proc sort data=manasi.cdrdata2_2004;
	by ssn;
run;

data manasi.kids_cdr04_mergeall_full;
	merge 	
			manasi.cdrdata2_2004 
			(rename=(ssn=hun dob=dob_cdr dobyy=dobyy_cdr sex=sex_cdr) in=fromcdrx
			drop=dis_off_cd score score_adr adj_level cus_cd guard_st 
			title_xvi ssr_sec ds_dia_cd ds_med_rea ds_per_dis bod_831 pri_831
			sec_831 med_831_re med_831_list dia_831 edu_831 adj_cdr body_833
			pri_833 sec_833 med_833_list dia_833 med_833_re dcf_pri_cd dcf_sec_cd)

			manasi.kids_ssr_full_nwithsummfypar 
			(in=fromssrx where=(n_estpd_num<20031001 & n_estpd_next>=20031001)
			drop=aptype mbrlaf cpstat race dt8080 xmitdo dencde dendte zebind
			do reptyp repcus n_diag2:);
	by hun; 
	fromcdr = fromcdrx;
	fromssr = fromssrx;
run;


* MERGE 2005 CDR-ELIGIBLES WITH THEIR SSR-OUTCOMES DATA;
proc sort data=manasi.cdrdata2_2005;
	by ssn;
run;

data manasi.kids_cdr05_mergeall_full;
	merge 	
			manasi.cdrdata2_2005 
			(rename=(ssn=hun dob=dob_cdr dobyy=dobyy_cdr sex=sex_cdr) in=fromcdrx 
			drop=dis_off_cd score score_adr adj_level cus_cd guard_st 
			title_xvi ssr_sec ds_dia_cd ds_med_rea ds_per_dis bod_831 pri_831
			sec_831 med_831_re med_831_list dia_831 edu_831 adj_cdr body_833
			pri_833 sec_833 med_833_list dia_833 med_833_re dcf_pri_cd dcf_sec_cd)

			manasi.kids_ssr_full_nwithsummfypar 
			(in=fromssrx where=(n_estpd_num<20041001 & n_estpd_next>=20041001)
			drop=aptype mbrlaf cpstat race dt8080 xmitdo dencde dendte zebind
			do reptyp repcus n_diag2:);

	by hun; 
	fromcdr = fromcdrx;
	fromssr = fromssrx;
run;


* TABULATE TO SEE HOW MANY RECORDS FROM CDR ELIGIBILITY FILE WERE MATCHED TO SSR;
proc tabulate data=manasi.kids_cdr02_mergeall_full;
	class fromcdr fromssr;
	table fromcdr, fromssr;
run;

proc tabulate data=manasi.kids_cdr03_mergeall_full;
	class fromcdr fromssr;
	table fromcdr, fromssr;
run;

proc tabulate data=manasi.kids_cdr04_mergeall_full;
	class fromcdr fromssr;
	table fromcdr, fromssr;
run;

proc tabulate data=manasi.kids_cdr05_mergeall_full;
	class fromcdr fromssr;
	table fromcdr, fromssr;
run;

* APPEND ALL FOUR YEARS TOGETHER;
data manasi.kids_cdryrs_mergeall_full;
	set manasi.kids_cdr02_mergeall_full
		manasi.kids_cdr03_mergeall_full
		manasi.kids_cdr04_mergeall_full
		manasi.kids_cdr05_mergeall_full;
run;

* MERGE 2006 CDR-ELIGIBLES WITH THEIR SSR-OUTCOMES DATA;
data manasi.cdrdata2_2006;
	set manasi.cdrdata2;
	if fy=2006;
run;

proc sort data=manasi.cdrdata2_2006;
	by ssn;
run;

data manasi.kids_cdr06_mergeall_full;
	merge 	
			manasi.cdrdata2_2006 
			(rename=(ssn=hun dob=dob_cdr dobyy=dobyy_cdr sex=sex_cdr) in=fromcdrx 
			drop=dis_off_cd score score_adr adj_level cus_cd guard_st 
			title_xvi ssr_sec ds_dia_cd ds_med_rea ds_per_dis bod_831 pri_831
			sec_831 med_831_re med_831_list dia_831 edu_831 adj_cdr body_833
			pri_833 sec_833 med_833_list dia_833 med_833_re dcf_pri_cd dcf_sec_cd)

			manasi.kids_ssr_full_nwithsummfypar 
			(in=fromssrx where=(n_estpd_num<20051001 & n_estpd_next>=20051001)
			drop=aptype mbrlaf cpstat race dt8080 xmitdo dencde dendte zebind
			do reptyp repcus n_diag2:);

	by hun; 
	fromcdr = fromcdrx;
	fromssr = fromssrx;
run;

* MERGE 2007 CDR-ELIGIBLES WITH THEIR SSR-OUTCOMES DATA;
data manasi.cdrdata2_2007;
	set manasi.cdrdata2;
	if fy=2007;
run;

proc sort data=manasi.cdrdata2_2007;
	by ssn;
run;

data manasi.kids_cdr07_mergeall_full;
	merge 	
			manasi.cdrdata2_2007 
			(rename=(ssn=hun dob=dob_cdr dobyy=dobyy_cdr sex=sex_cdr) in=fromcdrx 
			drop=dis_off_cd score score_adr adj_level cus_cd guard_st 
			title_xvi ssr_sec ds_dia_cd ds_med_rea ds_per_dis bod_831 pri_831
			sec_831 med_831_re med_831_list dia_831 edu_831 adj_cdr body_833
			pri_833 sec_833 med_833_list dia_833 med_833_re dcf_pri_cd dcf_sec_cd)

			manasi.kids_ssr_full_nwithsummfypar 
			(in=fromssrx where=(n_estpd_num<20061001 & n_estpd_next>=20061001)
			drop=aptype mbrlaf cpstat race dt8080 xmitdo dencde dendte zebind
			do reptyp repcus n_diag2:);

	by hun; 
	fromcdr = fromcdrx;
	fromssr = fromssrx;
run;


proc tabulate data=manasi.kids_cdr06_mergeall_full;
	class fromcdr fromssr;
	table fromcdr, fromssr;
run;

proc tabulate data=manasi.kids_cdr07_mergeall_full;
	class fromcdr fromssr;
	table fromcdr, fromssr;
run;
